var this_tinyimagepaste = null; (function() {
	tinymce.create("tinymce.plugins.tinyimagepaste", {
		ed: null,
		init: function(ed, url) {
			this.ed = ed;
			this_tinyimagepaste = this;
			setTimeout(this._hook, 1);
			ed.addButton("tinyimagepaste", {
				title: "Image Paste",
				onclick: function() {
					alert("直接粘贴图片就ok，有问题请反馈：https://www.wandhi.com")
				},
				image: url + "/ico.png"
			})
		},
		_paste: function(content) {
			return content
		},
		_hook: function() {
			var that = this;
			jQuery("html").find("iframe").contents().find("body").ready().pasteImageReader(function(results) {
				var dataURL, filename;
				filename = results.filename,
				dataURL = results.dataURL;
				var iframe = jQuery("#poststuff").find("iframe");
				var data = {
					action: "imagepaste_action",
					imgdata: results.dataURL,
					filename: results.filename,
					name: results.name
				};
				new jQuery.ajax({
					url: ajaxurl,
					type: "post",
					data: data,
					success: function(request) {
						var obj = eval("(" + request + ")");
						if (obj.error) {
							alert(obj.error)
						} else {
							var id = iframe.contents().find("body").attr("id");
							ed = this_tinyimagepaste.ed;
							ed.execCommand("mceInsertContent", false, this_tinyimagepaste._paste('<img src="' + obj.url + '" />'))
						}
					}
				})
			})
		}
	});
	tinymce.PluginManager.add("tinyimagepaste", tinymce.plugins.tinyimagepaste)
})();